﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class User : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
         string act = Request.QueryString["action"];
//         if(act == "login")
//         {
//            // Response.Write("qwe");
//            Response.Write("登陆失败");
//         }
//         else Response.Write("<form enctype=\"multipart/form-data\" name=\"form1\">用户名：<input type=\"text\" id=\"username\"><p>密码： <input type=\"text\" id=\"password\"></p><p><input type=\"button\" name=\"Submit\" value=\"登陆\" onclick=\"login();\" /><input type=\"button\" name=\"Submit2\" value=\"注册\" onclick=\"javascript:window.open='Register.aspx'\" /><input type=\"button\" name=\"Submit3\" value=\"忘记密码\" onclick=\"javascript:window.open='ForgetPassWord.aspx'\" /></p></form>");
//         return;
        switch(act)
        {
            case "login": 
                {
                    string username = Request.QueryString["username"];
                    string password = Request.QueryString["password"];
                    MysqlHelp AsUserLog = new MysqlHelp();
                   string conn = "select * from user where username='" + username + "'and password='" + password + "'";
                    DataTable UserBack = AsUserLog.GetDatabysql(conn);
                    if (UserBack.Rows.Count != 0)
                    {
                        Session["asusername"] = username;
                        Session["asprivilege"] = UserBack.Rows[0]["privilege"];
                        goto case "status";
                    }
                    else
                    {
                        Response.Write("用户名或密码错误！");
                    }
                }
                break;
            case "logout":Session.RemoveAll() ; break;
            case "status":
                if(Session["asusername"]!=null&&Session["asusername"].ToString()!="")
                {
                    Response.Write(string.Format("<p>欢迎您<font color=\"#F0FFD0\">{0}</font></p>", Session["asusername"].ToString()));
                }
                else
                {
                    Response.Write("<form enctype=\"multipart/form-data\" name=\"form1\">用户名：<input type=\"text\" id=\"username\"><p>密&nbsp;&nbsp;&nbsp;&nbsp;码：<input type=\"text\" id=\"password\"></p><p><input type=\"button\" name=\"Submit\" value=\"登陆\" onclick=\"login();\" /><input type=\"button\" name=\"Submit2\" value=\"注册\" onclick=\"javascript:window.open('Register.aspx')\" /><input type=\"button\" name=\"Submit3\" value=\"忘记密码\" onclick=\"javascript:window.open('ForgetPassWord.aspx')\" /></p></form>");
                }
                ;break;
            default:break;
        }
    }
}
